{extend name="public:base" /}

{block name="body"}

<div class="main" style="padding:15px;">
    <div class="content">
        <span style="margin-left: 0">收货地址</span>
        <button class="layui-btn layui-btn-xs" onclick="addAddress()">添加</button>
        <div></div>
    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th style="text-align: center;font-weight: bold">收货人</th>
            <th style="text-align: center;font-weight: bold">地址</th>
            <th style="text-align: center;font-weight: bold">手机号</th>
            <th style="text-align: center;font-weight: bold">创建时间</th>
            <th style="text-align: center;font-weight: bold">修改时间</th>
            <th style="text-align: center;font-weight: bold">默认地址</th>
            <th style="text-align: center;font-weight: bold">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="right" id='right'}
        <tr>
            <td style="text-align: center">{$right.name}</td>
            <td style="text-align: center">{$right.address}</td>
            <td style="text-align: center">{$right.mobile}</td>
            <td style="text-align: center">{$right.create_time|date='Y-m-d'}</td>
            <td style="text-align: center">{$right.update_time|date='Y-m-d'}</td>
            <td style="text-align: center">

                <input type="radio" name="is_default" value="1" id="ok" addid="{$right.id}"
                       {if $right.is_default == 1}checked="checked"{/if}>是&nbsp&nbsp
            </td>

            <td style="text-align: center" >
                <button class="layui-btn layui-btn-xs" id="cart1" onclick="modify({$right.id})">修改</button>
                <button class="layui-btn layui-btn-xs" id="cart1" onclick="delAddr({$right.id})">删除</button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>

</div>

<script>
    function addAddress(){
        layer.open({
            type: 2,
            title: '添加收货地址',
            shade: 0.3,
            area: ['800px', '400px'],
            content: '/index.php/user/addAddress'
        });
    }
</script>

<script>
    function modify(id){
        layer.open({
            type: 2,
            title: '添加收货地址',
            shade: 0.3,
            area: ['800px', '400px'],
            content: '/index.php/user/addrEdit?id='+id
        });
    }
</script>

<script>
    function delAddr(id){
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/index.php/user/delAddr',{'id':id},function(res){
                if(res.status==0){
                    layer.alert(res.message,{icon:2});
                }else{
                    layer.msg(res.message);
                    setTimeout(function(){window.location.reload();},1000);
                }
            },'json');
        });
    }
</script>

<script>
    $('input[type=radio][name=is_default]').change(function(){
        var addid = $(this).attr('addid');
        $.ajax({
            type: 'GET',
            url: "upDefault",
            data:{
                addid:addid,
            },
            dataType: 'json',
            success: function(data){
                if (data.status == 1) {
                    layer.msg(data.message);
                } else {
                    layer.msg(data.message);
                }
            }
        });
    });

</script>
{/block}